local gamelib = require "club.threecard.gamelib"
local game = require "club.threecard.bjracing"

local player_info = gamelib.ui.element()

player_info.store_watchers = 
{
    ingame = 
    {
        ["on_change_chip"] = function(self, store, state, args, isInitialize)
            if isInitialize then
                self:init();
            else
                self:update(args.old);
            end
         end
    }
}

function player_info:ctor()
    self.res = "club.threecard.bjracing/ui/gamescene.b:player_info";
    self.app = game;
end

function player_info:init()
    self.name_txt.text = game.kbe.player().name;
    self.chip_txt.text = string.format("$%s", game.kbe.player().chip);
end

function player_info:update(old)
    local currentValue = game.kbe.player().chip;
    self.chip_txt.text = currentValue;
end

return player_info